package com.atguigu.bean;

import java.util.List;

public class Page<T> {
    private String pageNostr;

    private Integer pageSize = 4;

    private Integer totalCount;

    private Integer pageNo;

    private Integer totalPage;

    private Integer index;


    private List<T> list;

    private String path;


    public String getPageNostr() {
        return pageNostr;
    }

    public void setPageNostr(String pageNostr) {
        this.pageNostr = pageNostr;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getPageNo() {
        pageNo = 1;
        try {
            pageNo = Integer.parseInt(pageNostr);
        } catch (NumberFormatException e) { }
        if (pageNo<=0) {
            pageNo = 1;
        }
        if (pageNo > getTotalPage()) {
            pageNo = getTotalPage();
        }
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getTotalPage() {
        totalPage = 0;
        if (totalCount % pageSize == 0) {
            totalPage = totalCount / pageSize;
        } else {
            totalPage = totalCount / pageSize + 1;
        }
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Integer getIndex() {
        return (getPageNo()-1)*pageSize;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }
}
